home *** CD-ROM | disk | FTP | other *** search
- /**
- -- Graphics Shell ("GX").c
- --
- -- This file is a shell that can be used to build "new" Graphics applications.
- -- It contains all of the required calls to use the "new" Graphics routines and
- -- QuickDraw (i.e. windows) together. It will put up one window. You "quit"
- -- the application by clicking in the close bix. This shell does not use a menu.
- --
- -- The application is expected to supply the following functions which are called
- -- by this shell:
- --
- -- void DoInitialization(WindowPtr);
- -- void DoDraw(WindowPtr);
- -- void DoDispose(WindowPtr);
- -- void DoClick(WindowPtr);
- -- void DoIdle(WindowPtr);
- --
- --
- -- Change History:
- --
- -- 3/90 New
- --
- -- 6/91 Updated the shell to reflect the changes in "Graphics" v1.0d21.2. PLA
- --
- -- 6/92 Made the following variables global: gDebugging, gGiveMeValidation,gGraphicsHeapSize.
- -- See the comments for detail in this file. PLA
- --
- -- 8/93 - Updated this file to run with the QD GX ß2 "GX-ified" interfaces
- -- - worked around a problem with GXConvertQDPoint (..) see the comments within
- -- the GetWindowBoundsShape (..) call for details (below). PLA
- --
- --
- -- © Apple Computer, Inc. 1990 - 1993 All rights reserved
- --
- **/
-
-
- #include <Desk.h>
- #include <Events.h>
- #include <Fonts.h>
- #include <Windows.h>
- #include <Memory.h>
- #include <ToolUtils.h>
- #include <Quickdraw.h>
-
- #include "graphics toolbox.h"
- #include "graphics routines.h"
- #include "graphics libraries.h"
- #include "graphics debugging.h"
- #include "graphics shell.h"
-
- #define kOSEvent app4Evt /* event used by MultiFinder */
- #define kSuspendResumeMessage 1 /* high byte of suspend/resume event message */
- #define kResumeMask 1 /* bit of message field for resume vs. suspend */
-
-
- WindowPtr gWindow, whichWindow;
-
- EventRecord gtheEvent;
- gxShape gWindowBoundsShape;
-
-
- /**------ Function Prototypes -----**/
- void main(void);
- gxShape GetWindowBoundsShape(void);
- Boolean EventLoop(void);
-
-
- /*------ main -----------------------------------------------------------------------------------------*/
-
- void main()
- {
- gxGraphicsClient client;
- gxViewPort theWindowsViewPort;
- CursHandle theCurs;
-
- /**
- The NewGraphicsClient routine defines the graphics heap size. If you do not make this call,
- the GX graphics engine will create this heap automatically. How? It will create a heap which
- is a percentage of your application's ideal memory foot print. This call allows you to explicity
- define the ammount of memory used by the graphics system for it's graphics objects heap.
- **/
- client = GXNewGraphicsClient(nil, gGraphicsHeapSize * 1024, 0L);
-
- /** Generic heap initialization. **/
- MaxApplZone();
- MoreMasters(); MoreMasters(); MoreMasters();
- MoreMasters(); MoreMasters(); MoreMasters();
-
- /**
- If gDebugging = TRUE, you will receive graphics library errors & notices will be posted. This
- functionality will only work with the "debugging" version of the Secret Graphics init. If this
- init is not installed, these functions will not work. The "debugging" version of the Secret
- Graphics init is approximately 700K.
- **/
- if (gDebugging) {
- SetGraphicsLibraryErrors ();
- SetGraphicsLibraryNotices();
- }
-
- /**
- Set "gGiveMeValidation" to TRUE, if you want run-time validation. As you increase the amount
- of validation, The drawing speed will SLOW down due to all of the internal checking.
-
- publicValidation will check parameters to public routines. For additional details regarding
- the various levels of validation, please see the documentation.
- **/
- if (gGiveMeValidation) GXSetValidation(gxPublicValidation + gxTypeValidation);
-
-
- /** initialize the new graphics environment **/
- GXEnterGraphics();
-
- /** initialize the toolbox **/
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitCursor();
-
- theCurs = GetCursor(watchCursor);
- SetCursor(*theCurs);
-
- /** Create a window and attach a default viewPort to it **/
- gWindow = NewWindow(nil, &gWindowQDRect, gWindowTitle, true, noGrowDocProc, (WindowPtr)-1L, true, 0L);
- theWindowsViewPort = GXNewWindowViewPort(gWindow);
-
- GXIgnoreGraphicsNotice(transform_already_set);
- SetDefaultViewPort(theWindowsViewPort);
- GXPopGraphicsNotice();
-
- /** Get the global bounds of the window **/
- gWindowBoundsShape = GetWindowBoundsShape();
-
- DoInitialization(gWindow);
-
- SetCursor(&qd.arrow);
-
- while (EventLoop())
- DoIdle(gWindow); /** loop until the window is closed **/
-
- DoDispose(gWindow);
-
- GXExitGraphics(); /** Deallocate all of the default structures **/
- GXDisposeGraphicsClient(client);
- }
-
-
-
- /*------ GetWindowBoundsShape -------------------------------------------------------------------------*/
-
- gxShape GetWindowBoundsShape()
- {
- Rect theRect;
- Point QDtopLeft;
- Point QDbotRight;
- gxPoint QDGXtopLeft;
- gxPoint QDGXbotRight;
- gxRectangle theQDGXRect;
- gxValidationLevel currentValidation;
-
- /** The QuickDraw rect and points which represent the portRect of the window. **/
- theRect = gWindow->portRect;
- QDtopLeft.h = theRect.left;
- QDtopLeft.v = theRect.top;
- QDbotRight.h = theRect.right;
- QDbotRight.v = theRect.bottom;
-
- //
- // Unfortunately, GXConvertQDPoint(..) will not survive validation with the QD GX ß2
- // seed. Therefore, we get the validation level set up by the application, and turn the
- // validation off. We will reset the validation to it's original setting below.
- //
- // This problem has already been fixed in the QD GX ß3 build, therefore this work around
- // will be removed at ß3. Details about the parameters for the GXConvertQDPoint (..) call
- // can be found in the QD GX ß2 Graphics Notes within the "• Open Me First •" folder.
- //
- currentValidation = GXGetValidation();
- if (currentValidation) GXSetValidation(gxNoValidation);
-
- /** Convert the global Quickdraw coordinates to local fixed coordinates. **/
- GXConvertQDPoint(&QDtopLeft, 0, &QDGXtopLeft);
- GXConvertQDPoint(&QDbotRight, 0, &QDGXbotRight);
-
- //
- // Reset the validation to the original setting.
- //
- if (currentValidation) GXSetValidation(currentValidation);
-
- /** Setup the dimensions for "gWindowBoundsShape" **/
- theQDGXRect.top = QDGXtopLeft.y;
- theQDGXRect.left = QDGXtopLeft.x;
- theQDGXRect.bottom = QDGXbotRight.y;
- theQDGXRect.right = QDGXbotRight.x;
-
- return (GXNewRectangle(&theQDGXRect));
- }
-
-
-
- /*------ EventLoop ------------------------------------------------------------------------------------*/
-
- Boolean EventLoop()
- {
- static long sleep = 0;
-
- WaitNextEvent(everyEvent, >heEvent, sleep, nil);
-
- switch(gtheEvent.what)
- {
- case updateEvt:
- BeginUpdate((WindowPtr) gtheEvent.message);
- SetPort(gWindow);
- DoDraw(gWindow);
- EndUpdate((WindowPtr) gtheEvent.message);
- break;
-
- case mouseDown:
- switch (FindWindow(gtheEvent.where, &whichWindow)) {
- case inSysWindow:
- SystemClick(>heEvent, whichWindow);
- break;
-
- case inDrag:
- DragWindow(whichWindow, gtheEvent.where, &qd.screenBits.bounds);
- break;
-
- case inGoAway:
- if (TrackGoAway(whichWindow, gtheEvent.where))
- return false;
- break;
-
- case inContent:
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- else
- DoClick(gWindow);
- break;
-
- }
-
- case kOSEvent:
- switch ((unsigned long) gtheEvent.message >> 24) { /** high byte of message **/
- case kSuspendResumeMessage: /** suspend/resume is also an activate/deactivate **/
- if ((gtheEvent.message & kResumeMask) == 0)
- sleep = 80; /** we are headed to the background, so slow down... **/
- else
- sleep = 0; /** we are headed to the foreground, so speed up... **/
- break;
- }
- break;
- }
- return true;
- }
-
-